#include "Box.h"


CBox::CBox()
{
}

CBox::CBox(VECTOR3 position)
{
	spriteVector_.push_back(new CSprite(L"Box//BOX_CLOSED.png", 1, 1, 1));
	spriteVector_.push_back(new CSprite(L"Box//BOX_OPENING.png", 1, 3, 3));
	spriteVector_.push_back(new CSprite(L"Box//BOX_OPENED.png", 1, 3, 3));
	this->position_			= position;
	this->velocity_			= VECTOR3(0, 0, 0);
	this->currentStatus_	= bStatus::BOX_CLOSED;
	this->isClosed_			= false;
	this->isOpen_			= false;
	this->count_			= 0;
}

CBox::~CBox()
{
}

void CBox::Update(DWORD deltaTime)
{

}

void CBox::Render()
{
	spriteVector_[currentStatus_]->Render(0, -1, this->position_);
}

void CBox::AI(VECTOR3 playerPosition)
{
	if (playerPosition.x > position_.x - 100)
	{
		this->isOpen_ = true;
	}
	if (this->isOpen_)
	{
		if (moveStatus(bStatus::BOX_OPEN))
		{
			this->isClosed_ = true;
			this->isOpen_ = false;
		}
	}
	if (this->isClosed_)
	{
		if (moveStatus(bStatus::BOX_CLOSED))
		{
			this->isOpen_ = true;
			this->isClosed_ = false;
		}
	}
}

void CBox::setStatus(bStatus status)
{
	if (currentStatus_ != status)
	{
		currentStatus_ = status;
	}
}

bool CBox::moveStatus(bStatus status)
{
	if (currentStatus_ == status)
		return true;
	count_++;
	if (currentStatus_ == bStatus::BOX_OPEN || currentStatus_ == bStatus::BOX_CLOSED)
	{
		if (count_ == SEC_OPEN_CLOSE)
		{
			count_ = 0;
			setStatus(currentStatus_ < status ? STATUS_NEXT : STATUS_BACK);
		}
	}
	else
	{
		if (count_ == SEC_MOVE)
		{
			count_ = 0;
			setStatus(currentStatus_ < status ? STATUS_NEXT : STATUS_BACK);
		}
	}
	
	return false;
}

bool CBox::changeStatus(bStatus status)
{
	count_++;
	if (count_ == SEC_MOVE)
	{
		setStatus(status);
		count_ = 0;
		return true;
	}
	return false;
}

